#include<reg52.h>

sbit key_s2=P3^0;
sbit DU = P2^6;
sbit WE = P2^7;

unsigned char n=0x01;
unsigned char m=0;
void delay(unsigned int z)
{
	unsigned int x,y;
	for(x = z; x > 0; x--)
		for(y = 114; y > 0 ; y--);
}

unsigned char table[2]={0x3F, 0x06};

 void display()
{
	P0=0XFF;
	WE=1;       
	P0=0XFE;
	WE=0;
	DU=1;
	P0=table[m/128%2];
	DU=0;
	delay(1);
	
	P0=0XFF;
	WE=1;     
	P0=0XFD;
	WE=0;
	DU=1;
	P0=table[m/64%2];
	DU=0;
	delay(1);
	
	P0=0XFF;
	WE=1;      
	P0=0XFB;
	WE=0;
	DU=1;
	P0=table[m/32%2];
	DU=0;
	delay(1);
	
	P0=0XFF;
	WE=1;      
	P0=0XF7;
	WE=0;
	DU=1;
	P0=table[m/16%2];
	DU=0;
	delay(1);
	
	P0=0XFF;
	WE=1;     
	P0=0Xef;
	WE=0;
	DU=1;
	P0=table[m/8%2];
	DU=0;
	delay(1);
	
	P0=0XFF;
	WE=1;      
	P0=0Xdf;
	WE=0;
	DU=1;
	P0=table[m/4%2];
	DU=0;
	delay(1);
	
	P0=0XFF;
	WE=1;    
	P0=0Xbf;
	WE=0;
	DU=1;
	P0=table[m/2%2];
	DU=0;
	delay(1);
	
	P0=0XFF;
	WE=1;     
	P0=0X7f;
	WE=0;
	DU=1;
	P0=table[m%2];
	DU=0;
	delay(1);
} 



void time0() interrupt 1
{   static unsigned char k=0;
		TH0=(65536-50000)/256;
		TL0=(65536-50000)%256;
		k++;
	 if(k>20)
			{ 
				k=0;
				n++;
				m++;
			} else if(key_s2==0){
			  n=~n;
				m=~m;
				
					
			}
			P1=~n;
  			
}

   
   


void main ()
{ 
	TMOD=0x01;
	TH0=(65536-50000)/256;
	TL0=(65536-50000)%256;
	TR0=1;
	EA=1;
	ET0=1;
	IT0=1;
	EX0=1;
	
	
	
	while(1)
	display();
	
}



